home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-04 / uldial.zip / ULDIAL.DOC < prev    next >
Text File  |  1990-07-12  |  19KB  |  439 lines

  1.      ╔════════════════════════════════════════════════════════════════╗
  2.      ║ Dialog Objects as Enhancements to Turbo Power OOP Professional ║
  3.      ║               New Communications Technology, Inc.              ║
  4.      ║                           Version 2.0                          ║
  5.      ║                       by John Poindexter                       ║
  6.      ║                         CIS 73717,3405                         ║
  7.      ║                          July 12, 1990                         ║
  8.      ║                       ┌───────┐┌────────┐                      ║
  9.      ║                       │ Ok    ││ Cancel │                      ║
  10.      ║                       └───────┘└────────┘                      ║
  11.      ╚════════════════════════════════════════════════════════════════╝
  12.  
  13. Version 2.0 of this unit makes some major improvements in encapsulating the
  14. details of the radio buttons and providing more flexibility in the
  15. instantiation of dialog boxes.
  16.  
  17. The main object of this unit is DialogBox, an object to display short messages
  18. or instructions, get user input if desired and exit using radio buttons. There
  19. is also a timeout provision so the box can be used for temporary messages that
  20. are to be displayed for a short period of time and then clear. The above logo
  21. is a simulation of what you will get. The new object RadioButtons is self
  22. contained and may be used in situations other than DialogBox.
  23.  
  24. Object hierarchy:
  25.  
  26.   [Root]              [Root]                         [Root]
  27.     DialogBox           [AbstractWindow]               [StringArray]
  28.                           [RawWindow]                    MStringArray
  29.                             [StackWindow]
  30.                               [CommandWindow]
  31.                                 [AbstractSelector]
  32.                                   EntryScreen
  33.                                 [PickList]
  34.                                   RadioButtons
  35.  
  36. DialogBox although an immediate descendant of Root contains an EntryScreenPtr
  37. field and RadioButtonsPtr fields and uses MStringArray which adds a data field
  38. and method that keep track of the maximum string length of added strings.
  39.  
  40. DialogBox has an automatic sizing feature which is the reason for making it an
  41. immediate descendant of Root rather than EntryScreen.
  42.  
  43. The minimal statements to use DialogBox look like this:
  44.  
  45.         if not MyDialog.Init(rbHoriz,1,30,2,20) then Exit;
  46.         with MyDialog do
  47.         begin
  48.           AddMessageString('This is a test of DialogBox.');
  49.           AddChoiceString('Ok Cancel');
  50.           AddHeader(' My Test ', heTC);
  51.           Process;
  52.           Code := GetLastChoice;
  53.           Done;
  54.         end;
  55.  
  56. Unit ULDial uses Unit ULRoot which is included in the archive. TESTDIAL.EXE is
  57. an interactive testing program that will give you an opportunity to try out
  58. DialogBox.
  59.  
  60. Types.
  61. ======
  62. HorizVerticalType = (rbHoriz, rbVertical);
  63.  
  64. Constants.
  65. ==========
  66. ucULDial = 201
  67.   Unit code for Unit ULDial.
  68.  
  69. scOk      = 0
  70. scCancel  = 1
  71. scRetry   = 2
  72. scTimeOut = 99
  73.   Status codes which may be used for exit status of DialogBox.
  74.  
  75. Variables.
  76. ==========
  77. ULRootColorSet : ColorSet
  78.   This is initialized to ULColorSet which is in ULRoot.
  79.  
  80. ButtonFrame : FrameArray
  81.   This is initialized to SglWindowFrame in ULDial.
  82.  
  83. Miscellaneous error codes and error messages are in ULRoot.
  84.  
  85. Objects.
  86. ========
  87. MStringArrayPtr = ^MStringArray
  88. MStringArray = object(StringArray)
  89.   msMaxLen : byte;
  90.   ...
  91.   function AddMString(St : string): word;
  92.   function GetMaxLen: byte;
  93. end;
  94.  
  95. RadioButtonsPtr = ^RadioButtons
  96. RadioButtons = object(PickList)
  97.   rbChoices : MStringArrayPtr;
  98.   rbOrient : HorizVerticalType;
  99.   ...
  100.   constructor Init();
  101.   destructor Done; virtual;
  102.   procedure ItemString(); virtual;
  103.   procedure ProcessSelf; virtual;
  104. end;
  105.  
  106. DialogBoxPtr = ^DialogBox;
  107. DialogBox = object(Root)
  108.   dlText : MStringArrayPtr;
  109.   dlChoices : MStringArrayPtr;
  110.   dlEntry : EntryScreenPtr;
  111.   dlButtons : RadioButtonsPtr;
  112.   ...
  113.   constructor Init();
  114.   constructor InitDeluxe();
  115.   destructor Done; virtual;
  116.   procedure Clear;
  117.   function GetLastError: word;
  118.   procedure Process; virtual;
  119.   procedure AddMessageString(Msg: string);
  120.   procedure AddChoiceString(Choice: string);
  121.   procedure AddChoice(Choice: string);
  122.   procedure AddHeader(S: string; Posn: HeaderPosType);
  123.   procedure AddStringEntryField();
  124.   function CreateBox: boolean; virtual;
  125.   function GetLastChoice: word;
  126.   function GetEditedString: string;
  127.   procedure SetTimeOut(Delay: word);
  128. end;
  129.  
  130. RadioButtons Methods.
  131. =====================
  132.  
  133. Declaration
  134.   constructor Init(X1,Y1,X2,Y2: byte; var Colors: ColorSet;
  135.                    Options: longint; Orientation: HorizVerticalType;
  136.                    NrRows, NrCols: byte; CharExit: boolean;
  137.                    CommandHandler: pkGenlProc;
  138.                    PickOptions: word; Choices: MStringArrayPtr);
  139. Purpose
  140.   Initialize this descendant of PickList which when drawn will display an
  141.   arrangement of radio buttons.
  142. Description
  143.   X1,Y1,X2,Y2 define the four corners of the active PickList window. They
  144.   should be calculated based on the width of the choices, the orientation, the
  145.   number of rows and number of columns of radio buttons. See DialogBox's
  146.   CreateBox method for and example of calculating these window coordinates.
  147.   Colors and Options are the normal parameters for windows. Orientation refers
  148.   to the arrangement of radio buttons. Note this is a different type parameter
  149.   from the one used in PickLists. The difference between rbHoriz and
  150.   rbVertical is in whether the radio buttons scroll horizontally or vertically
  151.   if there are more buttons than can be shown in the active window.
  152.   NrRows and NrCols refers to the number of rows and columns of radio buttons
  153.   and not to the number of character positions covered by the buttons. A
  154.   button looks like this:  ┌────────┐
  155.                            │ Cancel │
  156.                            └────────┘
  157.   The type of frame around the button may be changed by assigning a new value
  158.   to ButtonFrame.
  159.  
  160.   The first character of the choice inside the button will be highlighted.
  161.   CharExit defines whether the PickList search method used is PickCharSearch
  162.   (CharExit = false) or PickCharExit (CharExit = true) as defined in OPRO
  163.   manual page 4-199. CommandHandler and PickOptions are the same as you would
  164.   use for a PickList. Choices is the string array that contains the labels
  165.   that are placed in the radio buttons.
  166.  
  167.   Init assumes you will be using the standard CommandHandler, PickCommands,
  168.   and makes some adjustments to it depending on the orientation. Since radio
  169.   buttons are normally used in a dialog box that may have an entry field,
  170.   there needs to be a way of moving from the entry field to the buttons and
  171.   vice versa. For the horizontal arrangement cursor up is assigned to the exit
  172.   command ccUser0. For the vertical arrangement cursor left is assigned to
  173.   ccUser0.
  174.  
  175. Declaration
  176.   destructor Done; virtual
  177. Purpose
  178.   To dispose of the RadioButtons object and restore PickCommands to the
  179.   standard assignments.
  180. Description
  181.   It does not dispose of the Choices array.
  182.  
  183. Declaration
  184.   procedure ItemString(Item: word; Mode: pkMode; var IType: pkItemType;
  185.                        var IString: string); virtual;
  186. Purpose
  187.   This is a PickList ItemString method for returning the strings to be
  188.   displayed in the PickList.
  189. Description
  190.   In the case of RadioButtons this method is specially tailored to produce the
  191.   radio button icons with the labels contained in the Choice array. The top
  192.   and bottom rows of each button are separate items in the PickList display
  193.   and are give the the pkProtected attribute. The area of highlighting for the
  194.   selected choice is limited to exclude the frame charcters by using Flex
  195.   attributes.
  196.  
  197. Declaration
  198.   procedure ProcessSelf; virtual
  199. Purpose
  200.   To provide a seamless interface between the RadioButtons window field in an
  201.   entry screen and other fields in the entry screen.
  202. Description
  203.   This method overrides the standard PickList ProcessSelf. ccSelect and
  204.   ccMouseSel are changed to ccDone so that the selection of a radio button
  205.   choice will exit the entry screen Process. ccUser0 is changed to BackTab to
  206.   move back to earlier entry screen fields.
  207.  
  208. DialogBox Methods.
  209. ==================
  210.  
  211. Declaration
  212.   constructor Init(Orientation: HorizVerticalType;
  213.                    NumTextLines, TotalTextChars,
  214.                    NumChoices, TotalChoiceChars: word);
  215. Purpose
  216.   Initialize internal data fields and allocate MStringArrays for storing
  217.   lines of message text and choices.
  218. Description
  219.   Orientation is either rbHoriz or rbVertical as explained above.
  220.   NumTextLines is the maximum number of lines of text that you will want
  221.   displayed as a message in the DialogBox.
  222.            TotalTextChars = NumTextLines * AveLengthOfEachLine
  223.   NumChoices is the number of radio buttons that you want. Each radio button
  224.   displays one word from the ChoiceString.
  225.            TotalChoiceChars = NumChoices * (AveLenghtOfEachChoice + 4)
  226.   Since DialogBox uses a descendant of StringArrays for storing the lines of
  227.   message Text to be displayed and the Choices, it is good practice to
  228.   allocate your best estimate of the memory storage requirements through Init.
  229.   However the StringArrays can reallocate if there is enough memory.
  230.   Reallocation will fragment memory.
  231.  
  232.   For the EntryScreen field of DialogBox, Init uses the default
  233.   ULRootColorSet, the default window options DefWindowOptions+wBordered,
  234.   NrRows and NrCols equal 1, and CharExit equals false. Init will center the
  235.   dialog box on the screen, truncating and limiting the number of rows of
  236.   message lines to make everything fit in the screen space available.
  237.  
  238. Declaration
  239.   constructor InitDeluxe(X1, Y1: word; Options: longint;
  240.                          Colors: ColorSet;
  241.                          Orientation: HorizVerticalType;
  242.                          NrRows, NrCols: byte; CharExit: boolean;
  243.                          NumTextLines, TotalTextChars,
  244.                          NumChoices, TotalChoiceChars: word);
  245. Purpose
  246.   To provide more flexibility that the default based Init in instantiating a
  247.   DialogBox.
  248. Description
  249.   X1 and Y1 define the upper left corner of the EntryScreen that is created by
  250.   CreateBox. The actual position is adjusted so that the DialogBox will fit on
  251.   the screen. The visible DialogBox is actually an EntryScreen. Values of 0,0
  252.   will cause the box to be centered on the screen. Values of ScreenWidth and
  253.   ScreenHeight will always place the DialogBox in the lower right corner of
  254.   the screen.  Options define the window options used by the entry screen.
  255.   Orientation is as explained above. NrRows, NrCols and CharExit are as
  256.   explained under RadioButtons. The last 4 parameters are the same as for
  257.   Init.
  258.  
  259. Declaration
  260.   destructor Done; virtual;
  261. Purpose
  262.   Deallocate all memory associated with DialogBox.
  263. Description
  264.   This includes memory for EntryScreen, RadioButtons, Text and Choice Arrays.
  265.  
  266. Declaration
  267.   procedure Clear;
  268. Purpose
  269.   To set up the DialogBox for a new message and set of Choices.
  270. Description
  271.   This resets the Message and Choice arrays by disposing of them and then
  272.   reallocating at the same size. The EntryScreen is also disposed and all
  273.   DialogBox data fields reinitialized. It is useful in those situations where
  274.   you want to keep a DialogBox initialized and just keep sending new messages
  275.   and choices.  Using this technique limits heap fragmentation.
  276.  
  277. Declaration
  278.   function GetLastError: word;
  279. Purpose
  280.   To return the last error recorded by DialogBox.
  281. Description
  282.   Returns the error code and resets dlLastError to 0.
  283.  
  284. Declaration
  285.   procedure Process;
  286. Purpose
  287.   To activate the DialogBox in preparation for obtaining user input.
  288. Description
  289.   Process is a little different from other process methods in OPRO. It calls
  290.   the method CreateBox described below to create the radio buttons
  291.   (dlButtons^) and the EntryScreen (dlEntry^); add the text fields, the string
  292.   entry field (if there is one) and the window field (dlButtons^). It then calls
  293.   dlEntry^.Process and waits for an exit selection. Process uses the standard
  294.   OPRO EntryCommands and PickCommands sets. If UseMouse is defined, as it is
  295.   in ULDEFINE.INC, and a mouse is installed, the mouse is enabled. After an
  296.   exit selection has been made Process also erases the DialogBox. If
  297.   SetTimeOut has been used to set a delay time before the box is automatically
  298.   erased, Process first calls Draw.
  299.  
  300. Declaration
  301.   procedure AddMessageString(Msg: string);
  302. Purpose
  303.   To add message strings which will be displayed as TextFields in the entry
  304.   screen to be created.
  305. Description
  306.   You can add as many message strings as you want, but keep in mind that only
  307.   those that will display on a full screen will be displayed and the lines
  308.   will be truncated to fit in a full screen window with a border. The entry
  309.   screen window is sized automatically as described under CreateBox. The
  310.   maximum number of text lines that can be displayed is
  311.   (ScreenHeight-5-NumberOfStringFieldLines). You do not have to add a message
  312.   string if you just want the radio buttons. If you stay within the memory
  313.   allocation specified in Init, then this is not likely to fail. Otherwise you
  314.   should check GetLastError after adding. In the rbHoriz mode the message
  315.   strings are centered. If you don't want them centered, just pad your strings
  316.   with blanks.
  317.  
  318. Declaration
  319.   procedure AddChoice(Choice: string);
  320. Purpose
  321.   To add exit choices that will be displayed in the radio button icons.
  322. Description
  323.   Each Choice string is displayed as a label in a radio button icon. It is an
  324.   error (epFatal+ecNoChoice) not to add a Choice string and the string may not
  325.   be blank. If you stay within the memory allocation requirements specified in
  326.   Init, this is not likely to fail. Otherwise you should check GetLastError
  327.   after adding.
  328. Example
  329.   AddChoice('Sometimes');
  330.   AddChoice('Always');
  331.   AddChoice('Never On Sunday');
  332.  
  333.   This would result in the following radio buttons:
  334.           ┌─────────────────┐┌─────────────────┐┌─────────────────┐
  335.           │ Sometimes       ││ Always          ││ Never On Sunday │
  336.           └─────────────────┘└─────────────────┘└─────────────────┘
  337.           Choice: 1                  2                  3
  338.   The labels are not centered to take advantage of the PickList character
  339.   search procedures.
  340.  
  341. Declaration
  342.   procedure AddChoiceString(Choice: string);
  343. Purpose
  344.   To add exit choices that will be displayed in the radio button icons.
  345. Description
  346.   This works much like AddChoice but you can include several choices in the
  347.   Choice string.  Each word in the string is treated as a separate choice.
  348. Example
  349.   AddChoiceString('Sometimes Always Never_On_Sunday');
  350.  
  351. Declaration
  352.   procedure AddStringEntryField(Prompt: string; pRow, pCol: word;
  353.                                 Picture: string; fRow, fCol: word;
  354.                                 fWidth: byte; HelpIndex: word;
  355.                                 EditSt: string);
  356. Purpose
  357.   To add a string entry field to the DialogBox.
  358. Description
  359.   The use of this method is exactly the same as AddStringField in OPRO. The
  360.   positioning of the field is adjusted in CreateBox as necessary to center the
  361.   field just above the radio buttons. pCol and fCol are adjusted to center the
  362.   entry field inside the box in the rbHoriz mode; only their difference is
  363.   significant. pRow and fRow are only used to determine whether the prompt and
  364.   the field are on the same line or if not, which comes first. So the
  365.   difference between pRow and fRow is the only thing that is significant.
  366.  
  367. Declaration
  368.   procedure AddHeader(S: string; Posn: HeaderPosType);
  369. Purpose
  370.   To add a header on the frame of the DialogBox.
  371. Description
  372.   Works just like the similar method in OPRO on the dlEntry^. It can fail
  373.   because of insufficient memory.
  374.  
  375. Declaration
  376.   function GetLastChoice: word;
  377. Purpose
  378.   Returns the number of the Choice that is selected.
  379. Description
  380.   The exit Choices are numbered beginning with 1 in the sequence that they
  381.   appear in the Choice string in AddChoiceString. This should be called after
  382.   Process to get the exit selection.
  383.  
  384. Declaration
  385.   function GetEditedString: string;
  386. Purpose
  387.   Returns the edited string if AddStringEntryField has been used.
  388. Description
  389.   If no entry field has been added, it will always return a blank string.
  390.  
  391. Declaration
  392.   procedure SetTimeOut(Delay: word);
  393. Purpose
  394.   Used to set a time out period (in seconds) for DialogBox.
  395. Description
  396.   Sometimes it is useful to display a temporary message that is on the screen
  397.   for a fixed length of time (Delay). If the user presses a key, the timeout
  398.   feature is overridden and the DialogBox reverts to normal key and mouse
  399.   operation. If the DialogBox exits because of timeout, the GetLastChoice will
  400.   return a value of scTimeOut (presently = 99).
  401. Example
  402.           if not MyDialog.Init(rbHoriz,1,78,2,20) then Exit;
  403.           with MyDialog do
  404.           begin
  405.             AddMessageString('Test of timeout feature.');
  406.             AddChoiceString('Ok Cancel');
  407.             SetTimeOut(10);
  408.             Process;
  409.             Code := GetLastChoice;
  410.             Done;
  411.           end;
  412.  
  413.   If a key is not pressed within 10 seconds, Code = scTimeOut.
  414.   If {Enter} is pressed, MyDialog is erased and Code = 1.
  415.   If any other key is pressed, MyDialog reverts to normal operation.
  416.  
  417. Declaration
  418.   function CreateBox: boolean; virtual
  419. Purpose
  420.   Initializes entry screen and radio buttons and adds fields.
  421. Description
  422.   Normally CreateBox is called automatically by Process; however you may call
  423.   it separately if you want to use non-default features. If CreateBox is
  424.   called prior to Process, then it will not be called in Process. CreateBox
  425.   sizes the entry screen window based on the messages, choices and entry field
  426.   that are added. In the rbHoriz mode the radio buttons are centered at the
  427.   bottom of the window. If an entry field is added, it is centered just above
  428.   the radio buttons. In the rbVertical mode the radio buttons are at the right
  429.   hand side of the window and the entry field is placed just below the lines
  430.   of text. If all goes well, it returns true. When CreateBox exits, all
  431.   objects are initialized and ready for a call to Process or Draw. CreateBox
  432.   tries very hard to work with what you have given it to put the dialog box on
  433.   the screen either in the center or as close as possible to the position you
  434.   have defined using InitDeluxe.
  435.  
  436. Comments or suggestions are welcome. I intend to add some other field types to
  437. DialogBox such as a Directory window.
  438.  
  439.